/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package data;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
/**
 *
 * @author NS
 */
public class User_Update {
    private Connection conn = null;
    public User_Update(Connection conn){
        this.conn = conn;
    }
    public String Update(UserInfo usr){
        Statement update;
        try{
            update = conn.createStatement();
            
            System.out.println("ALTER USER " + usr.getUsername() +
                                 " IDENTIFIED BY " + usr.getPwd() +
                                 " DEFAULT TABLESPACE " + usr.getDefTbspace() +
                                 " TEMPORARY TABLESPACE " + usr.getTmpTbspace()+
                                 " QUOTA " + usr.getQuota() + " ON " + usr.getDefTbspace()+ 
                                 " ACCOUNT " + usr.getAccStatus() + 
                                 " PROFILE " + usr.getProfile());
            update.executeUpdate("ALTER USER " + usr.getUsername() +
                                 " IDENTIFIED BY " + usr.getPwd() +
                                 " DEFAULT TABLESPACE " + usr.getDefTbspace() +
                                 " TEMPORARY TABLESPACE " + usr.getTmpTbspace()+
                                 " QUOTA " + usr.getQuota() + " ON " + usr.getDefTbspace()+ 
                                 " ACCOUNT " + usr.getAccStatus() + 
                                 " PROFILE " + usr.getProfile());
            
            System.out.println("UPDATE USERTBL SET PASSWORD = '" +
                                 usr.getPwd() + "', DEFAULTTBSPACE = '" + 
                                 usr.getDefTbspace() + "', TEMPTBSPACE = '"+
                                 usr.getTmpTbspace() + "', ACC_STATUS = '" +
                                 usr.getAccStatus()  + "', QUOTA = '" +
                                 usr.getQuota() + "', PROFILE = '" +
                                 usr.getProfile() + "' WHERE USERNAME = '" +
                                 usr.getUsername() + "'");
            update.executeUpdate("UPDATE USERTBL SET PASSWORD = '" +
                                 usr.getPwd() + "', DEFAULTTBSPACE = '" + 
                                 usr.getDefTbspace() + "', TEMPTBSPACE = '"+
                                 usr.getTmpTbspace() + "', ACC_STATUS = '" +
                                 usr.getAccStatus()  + "', QUOTA = '" +
                                 usr.getQuota() + "', PROFILE = '" +
                                 usr.getProfile() + "' WHERE USERNAME = '" +
                                 usr.getUsername() + "'");
            
            return "success";
        }catch(SQLException e){
            System.err.println(e);
            return e.getMessage();
        }
    }
}
